package com.hpsk.shopgen.model.genbasic.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hpsk.common.RespResult;
import com.hpsk.common.RespUtils;
import com.hpsk.shopgen.model.genbasic.entity.GenBasic;
import com.hpsk.shopgen.model.genbasic.param.GenBasicAddParam;
import com.hpsk.shopgen.model.genbasic.param.GenBasicIdParam;
import com.hpsk.shopgen.model.genbasic.param.GenBasicPageParam;
import com.hpsk.shopgen.model.genbasic.result.GenBasicTableColumnResult;
import com.hpsk.shopgen.model.genbasic.result.GenBasicTableResult;
import com.hpsk.shopgen.model.genbasic.service.IGenBasicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 生成基础 前端控制器
 * </p>
 *
 * @author huangwang
 * @since 2025-07-07
 */
@RestController
@RequestMapping("/genBasic")
@Tag(name = "代码生成基础休息")
@Validated
public class GenBasicController {

    @Resource
    private IGenBasicService genBasicService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "获取所有表信息")
    @GetMapping("/getAllTableInfo")
    public RespResult<List<GenBasicTableResult>> getAllTableInfo() {
        return RespUtils.ok(genBasicService.getAllTableInfo());
    }

    @ApiOperationSupport(order = 2)
    @Operation(summary = "获取表内所有字段信息")
    @GetMapping("/tableColumns/{tableName}")
    public RespResult<List<GenBasicTableColumnResult>> tableColumns(@PathVariable String tableName) {
        return RespUtils.data(genBasicService.tableColumns(tableName));
    }


    @ApiOperationSupport(order = 3)
    @Operation(summary = "获取表内所有字段信息")
    @PostMapping("/add")
    public RespResult<GenBasic> add(@RequestBody @Valid GenBasicAddParam genBasicAddParam) {
        return RespUtils.data(genBasicService.add(genBasicAddParam));
    }

    @ApiOperationSupport(order = 4)
    @Operation(summary = "分页获取基础信息")
    @GetMapping("/page")
    public RespResult<IPage<GenBasic>> page(@ParameterObject @Valid GenBasicPageParam genBasicPageParam) {
        return RespUtils.data(genBasicService.page(genBasicPageParam));
    }
    @ApiOperationSupport(order = 5)
    @Operation(summary = "详情")
    @GetMapping("/detail")
    public RespResult<GenBasic> detail(@ParameterObject @Valid GenBasicIdParam genBasicIdParam) {
        return RespUtils.data(genBasicService.detail(genBasicIdParam));
    }

    @ApiOperationSupport(order = 5)
    @Operation(summary = "批量删除")
    @PostMapping("/batchDelete")
    public RespResult<Boolean> batchDelete(@RequestBody @Valid List<Long> genBasicIds) {
        boolean b = genBasicService.removeBatchByIds(genBasicIds);
        return RespUtils.ok();
    }

}
